module "wrapper" {
  source = "../../modules/flow-log"

  for_each = var.items

  cloudwatch_log_group_class             = try(each.value.cloudwatch_log_group_class, var.defaults.cloudwatch_log_group_class, null)
  cloudwatch_log_group_kms_key_id        = try(each.value.cloudwatch_log_group_kms_key_id, var.defaults.cloudwatch_log_group_kms_key_id, null)
  cloudwatch_log_group_name              = try(each.value.cloudwatch_log_group_name, var.defaults.cloudwatch_log_group_name, null)
  cloudwatch_log_group_retention_in_days = try(each.value.cloudwatch_log_group_retention_in_days, var.defaults.cloudwatch_log_group_retention_in_days, 90)
  cloudwatch_log_group_tags              = try(each.value.cloudwatch_log_group_tags, var.defaults.cloudwatch_log_group_tags, {})
  cloudwatch_log_group_use_name_prefix   = try(each.value.cloudwatch_log_group_use_name_prefix, var.defaults.cloudwatch_log_group_use_name_prefix, true)
  create                                 = try(each.value.create, var.defaults.create, true)
  create_cloudwatch_log_group            = try(each.value.create_cloudwatch_log_group, var.defaults.create_cloudwatch_log_group, true)
  create_iam_role                        = try(each.value.create_iam_role, var.defaults.create_iam_role, true)
  deliver_cross_account_role             = try(each.value.deliver_cross_account_role, var.defaults.deliver_cross_account_role, null)
  destination_options                    = try(each.value.destination_options, var.defaults.destination_options, null)
  eni_id                                 = try(each.value.eni_id, var.defaults.eni_id, null)
  flow_log_tags                          = try(each.value.flow_log_tags, var.defaults.flow_log_tags, {})
  iam_role_arn                           = try(each.value.iam_role_arn, var.defaults.iam_role_arn, null)
  iam_role_description                   = try(each.value.iam_role_description, var.defaults.iam_role_description, null)
  iam_role_name                          = try(each.value.iam_role_name, var.defaults.iam_role_name, null)
  iam_role_path                          = try(each.value.iam_role_path, var.defaults.iam_role_path, null)
  iam_role_permissions                   = try(each.value.iam_role_permissions, var.defaults.iam_role_permissions, null)
  iam_role_permissions_boundary          = try(each.value.iam_role_permissions_boundary, var.defaults.iam_role_permissions_boundary, null)
  iam_role_tags                          = try(each.value.iam_role_tags, var.defaults.iam_role_tags, {})
  iam_role_trust_policy_permissions      = try(each.value.iam_role_trust_policy_permissions, var.defaults.iam_role_trust_policy_permissions, null)
  iam_role_use_name_prefix               = try(each.value.iam_role_use_name_prefix, var.defaults.iam_role_use_name_prefix, true)
  kinesis_data_firehose_arn              = try(each.value.kinesis_data_firehose_arn, var.defaults.kinesis_data_firehose_arn, null)
  log_destination                        = try(each.value.log_destination, var.defaults.log_destination, null)
  log_destination_type                   = try(each.value.log_destination_type, var.defaults.log_destination_type, "cloud-watch-logs")
  log_format                             = try(each.value.log_format, var.defaults.log_format, null)
  max_aggregation_interval               = try(each.value.max_aggregation_interval, var.defaults.max_aggregation_interval, null)
  name                                   = try(each.value.name, var.defaults.name, "")
  region                                 = try(each.value.region, var.defaults.region, null)
  subnet_id                              = try(each.value.subnet_id, var.defaults.subnet_id, null)
  tags                                   = try(each.value.tags, var.defaults.tags, {})
  traffic_type                           = try(each.value.traffic_type, var.defaults.traffic_type, "ALL")
  transit_gateway_attachment_id          = try(each.value.transit_gateway_attachment_id, var.defaults.transit_gateway_attachment_id, null)
  transit_gateway_id                     = try(each.value.transit_gateway_id, var.defaults.transit_gateway_id, null)
  vpc_id                                 = try(each.value.vpc_id, var.defaults.vpc_id, null)
}
